#include <iostream>
#include <string>
#include <stack>

bool checkBrackets(const std::string& input) {
    std::stack<char> brackets;
    for (char ch : input) {
        if (ch == '(' || ch == '[' || ch == '{' || ch == '<') {
            brackets.push(ch);
        } else if (ch == ')' || ch == ']' || ch == '}' || ch == '>') {
            if (brackets.empty()) {
                return false;
            }
            char opening = brackets.top();
            if ((opening == '(' && ch == ')') ||
                (opening == '[' && ch == ']') ||
                (opening == '{' && ch == '}') ||
                (opening == '<' && ch == '>')) {
                brackets.pop();
            } else {
                return false;
            }
        }
    }
    return brackets.empty();
}

int main() {
    std::string input;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> input;

    if (checkBrackets(input)) {
        std::cout << "true" << std::endl;
    } else {
        std::cout << "false" << std::endl;
    }

    return 0;
}
